﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Drawing;
using GreatB2C.Utility;

namespace GreatB2C.Web.Manage.Shop
{
    public partial class ProviderManage : System.Web.UI.Page
    {
        Business.Provider BLL = new Business.Provider();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
            }
        }

        private void LoadData()
        {
            // 根据数据库对应的表，映射到相应的操作对象
            DataTable dtData = BLL.ListProvider();
            if (dtData.Rows.Count > 0)
            {
                AspNetPager1.RecordCount = dtData.Rows.Count;

                PagedDataSource pds = new PagedDataSource();
                pds.DataSource = dtData.DefaultView;
                pds.AllowPaging = true;
                pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
                pds.PageSize = AspNetPager1.PageSize;
                dgList.DataSource = pds;
                dgList.DataBind();

                dgList.Visible = true;
                litNone.Visible = false;
            }
            else
            {
                dgList.Visible = false;
                AspNetPager1.Visible = false;
                litNone.Text = "<div style='width:120px; margin:0 auto; margin-top:20px;'>没 有 任 何 数 据 ！</div>";
            }
        }

        protected void AspNetPager1_PageChanged(object src, EventArgs e)
        {
            LoadData();
        }

        protected void dgData_ItemDataBound(object sender, DataGridItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                //添加自定义属性，当鼠标移过来时设置该行的背景色,并保存原背景色
                e.Item.Attributes.Add("onmouseover", "this.className='tdbgmouseover';");
                //添加自定义属性，当鼠标移走时还原该行的背景色
                e.Item.Attributes.Add("onmouseout", "this.className='tdbg';");
                //添加双击事件
                e.Item.Attributes.Add("ondblclick", "RowDblclick('Provider.aspx?ProducerId=" + e.Item.Cells[1].Text.Trim() + "');"); 
            }
        }

        protected void dgData_ItemCommand(object source, DataGridCommandEventArgs e)
        {
            bool isSuccess = false;
            string id = e.CommandArgument.ToString();
            if (id.Trim() != "")
            {
                switch (e.CommandName)
                {
                    case "Update":
                        Response.Redirect("Provider.aspx?ProducerId=" + id);
                        break;
                    case "Delete":
                        break;
                }
            }
        }
    }
}
